package com.wantupai.mvp.framework.base.decoration.impl;

import android.content.Context;
import android.graphics.Canvas;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.wantupai.mvp.framework.base.decoration.BaseDividerItemDecoration;


/**
 * @author zhangqing
 * 填充两边的分割线
 */
public class HorizonationMatchparentDividerItemDecoration extends BaseDividerItemDecoration
{
    public HorizonationMatchparentDividerItemDecoration(Fragment fragment, int padding)
    {
        super(fragment);
        setPadding(padding);
    }
    public HorizonationMatchparentDividerItemDecoration(Context context, int padding)
    {
        super(context);
        setPadding(padding);
    }

    @Override
    public void drawVertical(Canvas canvas, RecyclerView parent, RecyclerView.State state)
    {
        final int left = parent.getPaddingLeft();
        final int right = parent.getWidth();

        final int childCount = parent.getChildCount();
        for (int i = 0; i < childCount; i++)
        {
            final View child = parent.getChildAt(i);
            final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
            final int top = child.getBottom() + params.bottomMargin;
            final int bottom = top + padding;
            mDrawable.setBounds(left, top, right, bottom);
            mDrawable.draw(canvas);
        }
    }
}
